import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/19 10:37
 * @description
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int numSubarraysWithSum(int[] nums, int goal) {
        int sum = 0;
        Map<Integer, Integer> cnt = new HashMap<Integer, Integer>();
        int ret = 0;
        for (int num : nums) {
            cnt.put(sum, cnt.getOrDefault(sum, 0) + 1);
            sum += num;
            ret += cnt.getOrDefault(sum - goal, 0);
        }
        return ret;

    }
}
